<?php
/**
 * CONTENIDO extension pack (mpContenidoX), consists of multiple classes to
 * provide more features for Plugins/Modules.
 *
 * @package     mpContenidoX
 * @subpackage  PluginInstaller
 * @author      Murat Purc <murat@purc.de>
 * @copyright   Copyright (c) 2008-2012 Murat Purc (http://www.purc.de)
 * @license     http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2
 * @version     $Id: Abstract.class.php 21 2012-07-16 21:33:14Z purcaholic $
 */


defined('CON_FRAMEWORK') or die('Illegal call');


/**
 * Abstract plugin bootstrap class, provides base features to initialize s.
 *
 * @package     mpContenidoX
 * @subpackage  PluginInstaller
 * @author      Murat Purc <murat@purc.de>
 */
abstract class mpPlugin_Bootstrap_Abstract
{

    /**
     * Pluginname
     * @var  string
     */
    protected $_pluginName;

    /**
     * Flag to store loaded status. Will be set to true in run() function.
     * @var  bool
     */
    protected $_run = false;

    /**
     * Time taken
     * @var  string
     */
    protected $_timeTaken = 0;


    /**
     * Constructor
     */
    protected function __construct()
    {
    }


    /**
     * Abstract function, is to call at least one for each plugin.
     *
     * @return void
     */
    abstract protected function _run();


    /**
     * Main function to initialize the plugin, is to call at least once for each plugin.
     *
     * @return void
     */
    public function run()
    {
        // check, if run method was invoked earlier
        if ($this->_run) {
            return;
        }
        $this->_run = true;

        // start timer
        $startTime = microtime(true);

        // call run method implemented by child class
        $this->_run();

        // store taken time for plugin bootstrapping
        $this->_timeTaken = microtime(true) - $startTime;

    }


    /**
     * Returns time taken
     *
     * @return  float
     */
     public function getTimeTaken()
     {
        return $this->_timeTaken;
     }

}
